let $ = layui.$;
/**
 * zmn渠道-工单视频
 * @author yangshuangping
 * @since 2021/06/08 15:12
 */
layui.define(['index', 'form', 'table', 'layer', 'laypage', 'layedit'], function (exports) {
    let form = layui.form;
    let table = layui.table;
    var layer = layui.layer;
    var laypage = layui.laypage;
    var layedit = layui.layedit;

    table.init('zmn-table', {
        toolbar: "#zmn-table-tool",
        defaultToolbar: [],
        page: true,
        limit: json.pageSize,
        height: 'full-149'
    });
    laypage.render(zmnPage.laypageOptions(json));
    /**
     * 修改后台审核标志
     */
    form.on("switch(chk_audit_flag)", function (obj) {
        let url = "/channel/workorder/video/updateAuditFlag.action";
        let id = obj.elem.getAttribute("key");
        let auditFlag = obj.elem.checked ? 2 : 1;
        switch (auditFlag) {
            case 1:
                zmnPage.ajaxSimple(url, {id: id, auditFlag: 1}, 1000);
                break;
            case 2:
                zmnPage.ajaxSimple(url, {id: id, auditFlag: 2}, 1000);
                break;
        }
    });
    /**
     *修改必传标志
     */
    form.on("switch(chk_required_flag)", function (obj) {
        let url = "/channel/workorder/video/updateRequiredFlag.action";
        let id = obj.elem.getAttribute("key");
        let requiredFlag = obj.elem.checked ? 2 : 1;
        switch (requiredFlag) {
            case 1:
                zmnPage.ajaxSimple(url, {id: id, requiredFlag: 1}, 1000);
                break;
            case 2:
                zmnPage.ajaxSimple(url, {id: id, requiredFlag: 2}, 1000);
                break;
        }
    });
    /**
     *修改排序
     */
    table.on("edit(zmn-table)", function (obj) {
        zmnPage.laySortPositiveInteger(obj.value, "/channel/workorder/video/updateSort.action", obj.data.id, 1000000, 1000);
    });

    //对外暴露的接口
    exports('channel_workorder_video_list', {});
});

function toAddWorkOrderVideo(channelId) {
    layer.open({
        type: 2,
        title: '上传视频',
        area: ['610px', '662px'],
        content: '/channel/workorder/video/addEditView.action?channelId=' + channelId
    });

}

function toEditWorkOrderVideo(channelId, id) {
    layer.open({
        type: 2,
        title: '修改视频',
        area: ['610px', '662px'],
        content: '/channel/workorder/video/addEditView.action?channnelId=' + channelId + "&id=" + id
    });
}

function deleteWorkOrderVideo(id) {
    layer.confirm('您确定要删除吗？', {
        btn: ['确定', '取消']
    }, function () {
        zmnPage.ajaxSimple("/channel/workorder/video/delete.action", {videoId: id}, 1000);
    });
}

function reload(msg) {
    parent.layui.layer.msg(msg);
    window.location.reload();
}

//显示描述
function show_tips(flag, tips, obj) {
    //小tips
    //如果没有权限则提示
    if (!flag) {
        layer.tips(tips, obj, {
            tips: [1, '#3595CC'],
            time: 3000
        })
    }
}

/**
 * 预览视频
 * @param element
 */
function previewVideo(videoId, videoSrc) {
    //调整预览大小
    let imgHtml = "<video src='" + videoSrc + "' id='channel" + videoId + "' style='width:96%;height:90%;margin:2%;'";
    imgHtml += "autoplay=‘autoplay’  controls='controls'/>";
    //弹出层
    layer.open({
        type: 1,
        shade: 0.8,
        offset: 'auto',
        area: [600 + 'px', 300 + 'px'],
        shadeClose: true,
        scrollbar: false,
        title: "", //不显示标题
        content: imgHtml, //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响
        cancel: function () {
            //layer.msg('捕获就是从页面已经存在的元素上，包裹layer的结构', { time: 5000, icon: 6 });
        }
    });
}
